package com.fengxing.ams.web.facade.mouble.plan;

import java.io.UnsupportedEncodingException;
import java.util.Set;

import org.springframework.stereotype.Repository;

import redis.clients.jedis.Jedis;

import com.fengxing.ams.web.common.SerializeUtil;
import com.fengxing.ams.web.facade.mouble.BaseRedis;

@Repository
public class PlanRedis extends BaseRedis implements
		IPlanRedis {
	
	@Override
	public void putCache(PlanCacheVO vo) {
		Jedis jedis = this.getJedis();
		
		try {
			String key = PLAN + vo.getYear() + vo.getSubject() + vo.getBatch() + vo.getCollege_id() + vo.getMajor_id();
			jedis.set(key.getBytes("UTF-8"), SerializeUtil.serialize(vo));
		} catch (UnsupportedEncodingException e) {
			e.printStackTrace();
		} finally {
			this.closeJedis(jedis);
		}
	}

	@Override
	public PlanCacheVO get(String key) {
		Jedis jedis = this.getJedis();
		
		try {
			byte[] b = jedis.get(key.getBytes("UTF-8"));
			return (PlanCacheVO) SerializeUtil.unserialize(b);
		} catch (UnsupportedEncodingException e) {
			e.printStackTrace();
		} finally {
			this.closeJedis(jedis);
		}
		return null;
	}
	
}
